<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<?php
session_start();
if(!isset($_SESSION["islogin"]) ) {
	echo "<meta http-equiv='refresh' content='0;URL= ../admin/index.php'>
	";
	return;
}
?>
	<meta name="keywords" content="jquery,ui,easy,easyui,web">
	<meta name="description" content="easyui help you build your web page easily!">
	<title>ADMIN-PAGE</title>
	<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/demo/demo.css">
	<style type="text/css">
		#fm{
			margin:0;
			padding:10px 30px;
		}
		.ftitle{
			font-size:14px;
			font-weight:bold;
			color:#666;
			padding:5px 0;
			margin-bottom:10px;
			border-bottom:1px solid #ccc;
		}
		.fitem{
			margin-bottom:5px;
		}
		.fitem label{
			display:inline-block;
			width:80px;
		}
	</style>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
	<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript">
		var url;
		function newUser(){
			$('#dlg').dialog('open').dialog('setTitle','Thêm sản phẩm mới');
			$('#fm').form('clear');
			url = 'save_user.php';
		}
		function editUser(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				$('#dlg').dialog('open').dialog('setTitle','Cập nhật sản phẩm');
				$('#fm').form('load',row);
				url = 'update_user.php?id='+row.id_sanpham;
			}
		}
		function saveUser(){
			$('#fm').form('submit',{
				url: url,
				onSubmit: function(){
					return $(this).form('validate');
				},
				success: function(result){
					var result = eval('('+result+')');
					if (result.success){
						$('#dlg').dialog('close');		// close the dialog
						$('#dg').datagrid('reload');	// reload the user data
					} else {
						$.messager.show({
							title: 'Error',
							msg: result.msg
						});
					}
				}
			});
		}
		function removeUser(){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				$.messager.confirm('Confirm','Are you sure you want to remove this user?',function(r){
					if (r){
						$.post('remove_user.php',{id:row.id_sanpham},function(result){
							if (result.success){
								$('#dg').datagrid('reload');	// reload the user data
							} else {
								$.messager.show({	// show error message
									title: 'Error',
									msg: result.msg
								});
							}
						},'json');
					}
				});
			}
		}
	</script>
</head>
<body>
	<a href="../admin/index.php" >
		<img style="border:2px black solid;" src="../img/mono-icons/leftarrow32.png"></a>
	<br>

	<h2>Sản Phẩm</h2>
	<div class="demo-info" style="margin-bottom:10px">
		<div class="demo-tip icon-tip">&nbsp;</div>
		<div>
			Export Sản Phẩm vào file *.csv
			<a href="export.php">Click</a>
			
		</div>

	</div>

	<div class="demo-info" style="margin-bottom:10px">
		<div class="demo-tip icon-tip">&nbsp;</div>
		<div>
			Import Sản Phẩm từ file *.csv
			<a href="import.php">Click</a>
			<form method="post" enctype="multipart/form-data" action="upload.php">
				<input type="file" name="importdt">
				<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
				<input name="upload" type="submit" id="upload" value="Upload">
			</form>
			<div style="float:right;">
				<?php echo ""."<a href='../admin/thoat.php'>
				"."
				<img src='../img/mono-icons/leftturnarrow32.png'>".'</a>';?>
			</div>
		</div>

	</div>
	
	<table id="dg" title="SẢN PHẨM" class="easyui-datagrid" style="width:800px;height:400px"
			url="get_users.php"
			toolbar="#toolbar" pagination="true"
			rownumbers="true" fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<th field="id_sanpham" width="10">ID SP</th>
				<th field="tensanpham" width="10">Tên SP</th>
				<th field="hinhsanpham" width="10">Hinh</th>
				<th field="id_danhmuc" width="10">Loại</th>
				<th field="l" width="10">L</th>
				<th field="h" width="10">H</th>
				<th field="w" width="10">W</th>
				<th field="d" width="10">D</th>

			</tr>
		</thead>
	</table>
	<div id="toolbar">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">Thêm SP</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Chỉnh sửa</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeUser()">Xóa</a>
	</div>

	<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
			closed="true" buttons="#dlg-buttons">
		<div class="ftitle">Thông tin sản phẩm</div>
		<form id="fm" method="post" novalidate>
			<div class="fitem">
				<label>Tên sản phẩm:</label>
				<input name="tensanpham" class="easyui-validatebox" required="true"></div>
			<div class="fitem">
				<label>Hình ảnh:</label>
				<input name="hinhsanpham" class="easyui-validatebox" ></div>
			<div class="fitem">
				<label>Giá:</label>
				<input name="gia"></div>
			<div class="fitem">
				<label>Thuộc danh mục:</label>
				<input name="id_danhmuc" class="easyui-validatebox" ></div>
			<div class="fitem">
				<label>Ngày cập nhật:</label>
				<input name="ngaycapnhat" class="easyui-validatebox" ></div>
			<div class="fitem">
				<label>Tình trạng:</label>
				<input name="tinhtrang" class="easyui-validatebox" ></div>
		</form>
	</div>
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">Lưu</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Hủy</a>
	</div>
</body>
</html>